package com.atguigu.juc.study.chapter04.locks;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author : leimingchao
 * @date Date : 2022年06月12日 14:40
 */
public class ReEntryLockDemo2 {

    static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {

        new Thread(() -> {

            lock.lock();
            try {

                System.out.println(Thread.currentThread().getName() + "\t ----come in 外层调用");

                lock.lock();

                try {
                    System.out.println(Thread.currentThread().getName() + "\t ----come in 内层调用");
                } finally {
                    lock.unlock();
                }
            } finally {
                lock.unlock();
            }

        }, "t1").start();


        new Thread(() -> {

            lock.lock();
            try {

                System.out.println(Thread.currentThread().getName() + "\t ----come in 外层调用");

            } finally {
                lock.unlock();
            }

        }, "t2").start();
    }
}
